package cn.wokoba.service.activity.service.discount.Impl;

import cn.wokoba.service.activity.model.valobj.GroupBuyActivityDiscountVO;
import cn.wokoba.service.activity.service.discount.AbstractDiscountCalculateService;
import cn.wokoba.types.common.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service("MJ")
@Slf4j
public class MJCalculateService extends AbstractDiscountCalculateService {
    @Override
    protected BigDecimal doCalculate(BigDecimal originalPrice, GroupBuyActivityDiscountVO.GroupBuyDiscount groupBuyDiscount) {
        log.info("优惠策略折扣计算:{}", groupBuyDiscount.getDiscountType().getInfo());

        String marketExpr = groupBuyDiscount.getMarketExpr();
        String[] split = marketExpr.split(Constants.SPLIT);
        BigDecimal LimitedAmount = new BigDecimal(split[0].trim());
        BigDecimal DeductionAmount = new BigDecimal(split[1].trim());
        //不满足满减金额
        if (originalPrice.compareTo(LimitedAmount) < 0) {
            return originalPrice;
        }
        return originalPrice.subtract(DeductionAmount);

    }
}
